import { defineStore } from 'pinia'
import router from '@/router'

export const useUserStore = defineStore('user', {
    state:() => ({
      token: '',
    }),
    actions: {
      setToken(token) {
          this.token = token
      },

      logout() {
          this.token = ''
          router.push({path: '/login'})
      }
    },
    getters: {
        getToken: (state) => {
            return state.token
        }
    },
    persist: {
        enabled: true,
        strategies: [
            {
                key: 'user',
                storage: localStorage,
                path:[] //可以选择保存的字段  其余的不保存
            }
        ]
    }
})

